#include "AppManager.h"
/*
static const uint8_t RTCOffset_bits[] = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0xfe, 0x7f, 0x00,
    0x80, 0x1f, 0xf8, 0x01, 0xc0, 0x03, 0xe0, 0x03, 0xe0, 0x01, 0x80, 0x07,
    0xf0, 0x00, 0x00, 0x0f, 0x78, 0x80, 0x01, 0x1e, 0x38, 0x80, 0x01, 0x1c,
    0x1c, 0x80, 0x01, 0x38, 0x1c, 0x80, 0x01, 0x30, 0x0e, 0x80, 0x01, 0x70,
    0x0e, 0x80, 0x01, 0x70, 0x06, 0x80, 0x01, 0x60, 0x06, 0x80, 0x01, 0x60,
    0x06, 0x80, 0x01, 0x60, 0x06, 0x8c, 0x03, 0x60, 0x06, 0x9b, 0x07, 0x60,
    0x86, 0x09, 0x0e, 0x60, 0x8e, 0x44, 0x1c, 0x70, 0x8e, 0xe4, 0x38, 0x30,
    0x9c, 0x9c, 0x10, 0x38, 0xdc, 0x40, 0x00, 0x38, 0x78, 0x60, 0x00, 0x1c,
    0x38, 0x3e, 0x00, 0x1e, 0x18, 0x03, 0x00, 0x0f, 0x8c, 0x01, 0x80, 0x07,
    0xc6, 0x07, 0xe0, 0x03, 0xe2, 0x1f, 0xf8, 0x01, 0x31, 0xfe, 0x7f, 0x00,
    0x1a, 0xf8, 0x0f, 0x00, 0x04, 0x00, 0x00, 0x00};
*/
class AppRTCOffset : public AppBase
{
private:
    /* data */
public:
    AppRTCOffset()
    {
        name = "rtcoffset";
        title = "误差补偿";
        description = "RTC线性误差补偿查看工具";
        image = NULL;
        _showInList = false;
    }
    void setup();
};
static AppRTCOffset app;

static void RTCOffsetTimer()
{
    display.setFullWindow();
    display.clearScreen();
    GUI::drawWindowsWithTitle("RTC线性误差补偿", 0, 0, 296, 128);
    u8g2Fonts.setCursor(0, 30);
    time_t now;
    tm rtctime;
    time(&now);
    localtime_r(&now, &rtctime);
    u8g2Fonts.printf("  %02d:%02d:%02d -> %02d:%02d:%02d\n", rtctime.tm_hour, rtctime.tm_min, rtctime.tm_sec, hal.timeinfo.tm_hour, hal.timeinfo.tm_min, hal.timeinfo.tm_sec);
    if (hal.lastsync != 1)
    {
        u8g2Fonts.printf("  上次同步时Unix时间：%d\n", hal.lastsync);
    }
    else
    {
        u8g2Fonts.printf("  从未同步时间或时间丢失\n");
    }
    if (hal.every != 100)
    {
        u8g2Fonts.printf("  当前误差数据：每%d分钟误差%d秒\n", hal.every / 60, hal.delta);
    }
    else
    {
        u8g2Fonts.printf("  RTC误差未知\n");
    }
    display.display();
}

void AppRTCOffset::setup()
{
    RTCOffsetTimer();
    appManager.setTimer(15, RTCOffsetTimer);
    appManager.noDeepSleep = true;
}
